<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template.xhtml">
	<ui:define name="corpo">

		<h:form id="formAula">
			<p:growl id="growl" life="2500"></p:growl>
			<p:dialog header="Detalhes" widgetVar="dialogAula" modal="true"
				closable="true">
				<p:outputPanel id="gridAula" style="text-align:center;"
					layout="block">
					<h:panelGrid columns="2" style="margin:0px" id="panelAula">

						<h:outputLabel for="prof" value="Professor: " />
						<h:outputText id="prof"
							value="#{aulaBean.aula.competencia.professor.usuario.nome}" />

						<h:outputLabel for="dia" value="Dia: " />
						<h:outputText id="dia"
							value="#{aulaBean.aula.disponibilidade.dia.dia}" />

						<h:outputLabel for="hor" value="Horario: " />
						<h:outputText id="hor"
							value="#{aulaBean.aula.disponibilidade.horario}" />

						<h:outputLabel for="tur" value="Turno: " />
						<h:outputText id="tur"
							value="#{aulaBean.aula.disponibilidade.turno.turno}" />

						<h:outputText value="Disciplina: "
							rendered="#{aulaBean.auxiliarAula != null}" />

						<p:selectOneMenu id="selectCompetencia"
							value="#{aulaBean.aula.competencia.disciplina}"
							converter="disciplinaConverter"
							rendered="#{aulaBean.auxiliarAula != null}">

							<f:selectItems value="#{aulaBean.disciplinasDispIndis}"
								var="disp" itemLabel="#{disp.nome}" itemValue="#{disp}"></f:selectItems>

							<p:ajax update="panelAula" />
						</p:selectOneMenu>

						<h:outputText value="Unidade: " id="textUnidade"
							rendered="#{aulaBean.aula.competencia.disciplina.nome == 'Disponível'}" />

						<p:selectOneMenu id="selectUnidade"
							value="#{aulaBean.aula.unidade}"
							rendered="#{aulaBean.aula.competencia.disciplina.nome == 'Disponível'}"
							converter="unidadeConverter">

							<f:selectItems value="#{aulaBean.unidades}" var="uni"
								itemLabel="#{uni.nome}" itemValue="#{uni}"></f:selectItems>

						</p:selectOneMenu>
						<p:commandLink actionListener="#{aulaBean.grava}"
							title="Cadastrar" update=":formDatagrid growl"
							oncomplete="lidaCadastroAula(xhr, status, args)"
							rendered="#{aulaBean.auxiliarAula != null}">
							<p:graphicImage value="resources/imagens/ok.png"></p:graphicImage>
						</p:commandLink>

						<p:commandLink title="Cancelar" onclick="dialogAula.hide()"
							rendered="#{aulaBean.auxiliarAula != null}">
							<p:graphicImage value="resources/imagens/cancelar.png"></p:graphicImage>
						</p:commandLink>

						<f:facet name="footer">
							<h:outputText
								value="Somente a secretaria pode mudar uma aula cadastrada"
								rendered="#{aulaBean.auxiliarAula == null}" />
						</f:facet>

						<script type="text/javascript">
							function lidaCadastroAula(xhr, status, args) {
								if (args.validationFailed || !args.gravado) {
									jQuery('dialogAula').effect("shake", {
										times : 3
									}, 100);
								} else {

									dialogAula.hide();
								}
							}
						</script>

					</h:panelGrid>

				</p:outputPanel>
			</p:dialog>
		</h:form>

		<h:form id="formDatagrid">
			<h2>Área do professor</h2>
			<p:commandButton oncomplete="wPrint.show()"
				value="Visualizar impressão" update=":impressao:grid" />

			<br></br>
			<br></br>


			<p:panelGrid style="margin-top:20px" id="grid">
				<f:facet name="header">
					<p:row>
						<p:column colspan="8" style="text-align:center;font-size:22px;">Grade do Professor</p:column>
					</p:row>
				</f:facet>
				<f:facet name="footer">
					<p:row>
						<p:column colspan="8">
							<div style="font-size: medium;">
								<h:outputLabel value="Nome:" for="inputNome" />
								<b><h:outputText id="inputNome"
										value="#{loginBean.usuario.nome} #{loginBean.usuario.sobrenome}"
										readonly="true" /></b><br />
								<h:outputLabel value="Matrícula" for="inputMatricula" />
								<b><h:outputText id="inputMatricula"
										value="#{loginBean.usuario.matricula}" readonly="true" /></b>
							</div>
						</p:column>
					</p:row>

					<p:row>

						<p:column style="text-align: center;">  
                Turno  
            			</p:column>
						<p:column style="text-align: center;">  
                Horario	  
            			</p:column>

						<p:column colspan="6">
							<p:dataGrid id="teste01" var="todosDias" value="#{aulaBean.dias}"
								columns="6" style="border: none;"
								emptyMessage="Selecione um professor">
								<p:column>


									<div align="center" style="width: 96px;">#{todosDias}</div>

								</p:column>
							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>

						<p:column style="text-align: center;" rowspan="2">  
               Matutino   
            </p:column>
						<p:column style="text-align: center;">
					1º
				</p:column>
						<p:column colspan="6">
							<p:dataGrid id="gridMatutino1" var="varMatutino1"
								value="#{aulaBean.aulasMat1}" columns="6" style="border: none;"
								emptyMessage="Selecione um professor">
								<p:column>

									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino1.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											#{varMatutino1.competencia.disciplina.nome}
											#{varMatutino1.unidade.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino1.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 96px; color: red">
											#{varMatutino1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino1.competencia.disciplina.nome != 'Indisponível' 
										and varMatutino1.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varMatutino1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>

								</p:column>

							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="text-align: center;">
						2º
						</p:column>

						<p:column colspan="6">
							<p:dataGrid id="gridMatutino2" var="varMatutino2"
								value="#{aulaBean.aulasMat2}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column>

									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino2.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											#{varMatutino2.competencia.disciplina.nome}
											#{varMatutino2.unidade.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino2.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 96px; color: red">
											#{varMatutino2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varMatutino2.competencia.disciplina.nome != 'Indisponível' 
										and varMatutino2.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varMatutino2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>


								</p:column>


							</p:dataGrid>
						</p:column>
					</p:row>

					<p:row>

						<p:column style="text-align: center;" rowspan="2">  
                Noturno  
            </p:column>
						<p:column style="text-align: center;">
					1º
				</p:column>
						<p:column colspan="6">
							<p:dataGrid id="gridNoturno1" var="varNoturno1"
								value="#{aulaBean.aulasNot1}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column
									rendered="#{!aulaBean.isSabado(varNoturno1.disponibilidade.dia)}">

									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno1.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											#{varNoturno1.competencia.disciplina.nome}
											#{varNoturno1.unidade.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno1.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 96px; color: red">
											#{varNoturno1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno1.competencia.disciplina.nome != 'Indisponível' 
										and varNoturno1.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varNoturno1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>


								</p:column>
								<p:column
									rendered="#{aulaBean.isSabado(varNoturno1.disponibilidade.dia)}">
									<p:commandLink>
										<div style="width: 96px"></div>
									</p:commandLink>
								</p:column>

							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="text-align: center;">
						2º
						</p:column>

						<p:column colspan="6">
							<p:dataGrid id="gridNoturno2" var="varNoturno2"
								value="#{aulaBean.aulasNot2}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column
									rendered="#{!aulaBean.isSabado(varNoturno2.disponibilidade.dia)}">
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno2.competencia.disciplina.nome == 'Disponível'}">
										<div align="center" style="width: 96px; color: blue">
											#{varNoturno2.competencia.disciplina.nome}
											#{varNoturno2.unidade.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno2.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 96px; color: red">
											#{varNoturno2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
									<p:commandLink oncomplete="dialogAula.show()"
										update=":formAula:gridAula"
										rendered="#{varNoturno2.competencia.disciplina.nome != 'Indisponível' 
										and varNoturno2.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 96px; color: black">
											#{varNoturno2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
								</p:column>
								<p:column
									rendered="#{aulaBean.isSabado(varNoturno2.disponibilidade.dia)}">
									<div style="width: 96px"></div>
								</p:column>




							</p:dataGrid>
						</p:column>
					</p:row>
				</f:facet>
			</p:panelGrid>
		</h:form>

		<h:form id="impressao">
			<p:dialog widgetVar="wPrint" id="idPrint" modal="true"
				resizable="false">


				<p:commandButton value="Imprimir" ajax="false">
					<p:printer target="grid"></p:printer>
				</p:commandButton>

				<p:panelGrid id="grid">
					<p:row>
						<p:column colspan="8">
							<div id="cabecalho">
								<h:graphicImage library="imagens" name="logo.gif"
									id="logoCompany" />
							</div>
						</p:column>
						<p:column rowspan="9">

						</p:column>
					</p:row>

					<p:row>
						<p:column colspan="8" style="text-align:center;font-size:22px;">Grade do Professor</p:column>
					</p:row>

					<p:row>
						<p:column colspan="8" style="font-size:16px;">
							<h:outputLabel value="Nome:" for="inputNome" />
							<b><h:outputText id="inputNome"
									value="#{loginBean.usuario.nome} #{loginBean.usuario.sobrenome}"
									readonly="true" /></b>
							<br />
							<h:outputLabel value="Matrícula" for="inputMatricula" />
							<b><h:outputText id="inputMatricula"
									value="#{loginBean.usuario.matricula}" readonly="true" /></b>
						</p:column>
					</p:row>

					<p:row>

						<p:column style="text-align: center;">  
                Turno  
            			</p:column>
						<p:column style="text-align: center;">  
                Horario	  
            			</p:column>

						<p:column colspan="6">
							<p:dataGrid id="teste01" var="todosDias" value="#{aulaBean.dias}"
								columns="6" style="border: none;"
								emptyMessage="Selecione um professor">
								<p:column>


									<div align="center" style="width: 80px; color: black">
										#{todosDias}</div>

								</p:column>
							</p:dataGrid>
						</p:column>

					</p:row>
					<p:row>

						<p:column style="text-align: center;" rowspan="2">  
               Matutino   
            </p:column>
						<p:column style="text-align: center;">
					1º
				</p:column>
						<p:column colspan="6">
							<p:dataGrid id="gridMatutino1" var="varMatutino1"
								value="#{aulaBean.aulasMat1}" columns="6" style="border: none;"
								emptyMessage="Selecione um professor">
								<p:column>

									<p:commandLink
										rendered="#{varMatutino1.competencia.disciplina.nome == 'Disponível' or varMatutino1.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 80px; color: blue">
											Vago</div>
									</p:commandLink>
									<p:commandLink update=":formAula:gridAula"
										rendered="#{varMatutino1.competencia.disciplina.nome != 'Indisponível' 
										and varMatutino1.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 80px; color: black">
											#{varMatutino1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>

								</p:column>

							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="text-align: center;">
						2º
						</p:column>

						<p:column colspan="6">
							<p:dataGrid id="gridMatutino2" var="varMatutino2"
								value="#{aulaBean.aulasMat2}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column>

									<p:commandLink
										rendered="#{varMatutino2.competencia.disciplina.nome == 'Disponível' or varMatutino2.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 80px; color: blue">
											Vago</div>
									</p:commandLink>
									<p:commandLink update=":formAula:gridAula"
										rendered="#{varMatutino2.competencia.disciplina.nome != 'Indisponível' 
										and varMatutino2.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 80px; color: black">
											#{varMatutino2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varMatutino2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>


								</p:column>


							</p:dataGrid>
						</p:column>
					</p:row>

					<p:row>

						<p:column style="text-align: center;" rowspan="2">  
                Noturno  
            </p:column>
						<p:column style="text-align: center;">
					1º
				</p:column>
						<p:column colspan="6">
							<p:dataGrid id="gridNoturno1" var="varNoturno1"
								value="#{aulaBean.aulasNot1}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column
									rendered="#{!aulaBean.isSabado(varNoturno1.disponibilidade.dia)}">

									<p:commandLink
										rendered="#{varNoturno1.competencia.disciplina.nome == 'Disponível' or varNoturno1.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 80px; color: blue">
											Vago</div>
									</p:commandLink>
									<p:commandLink update=":formAula:gridAula"
										rendered="#{varNoturno1.competencia.disciplina.nome != 'Indisponível' 
										and varNoturno1.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 80px; color: black">
											#{varNoturno1.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno1}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>


								</p:column>
								<p:column
									rendered="#{aulaBean.isSabado(varNoturno1.disponibilidade.dia)}">
									<p:commandLink>
										<div style="width: 80px"></div>
									</p:commandLink>
								</p:column>

							</p:dataGrid>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="text-align: center;">
						2º
						</p:column>

						<p:column colspan="6">
							<p:dataGrid id="gridNoturno2" var="varNoturno2"
								value="#{aulaBean.aulasNot2}" columns="6" style="border: none;"
								emptyMessage="-">
								<p:column
									rendered="#{!aulaBean.isSabado(varNoturno2.disponibilidade.dia)}">
									<p:commandLink
										rendered="#{varNoturno2.competencia.disciplina.nome == 'Disponível' or varNoturno2.competencia.disciplina.nome == 'Indisponível'}">
										<div align="center" style="width: 80px; color: blue">
											Vago</div>
									</p:commandLink>
									<p:commandLink update=":formAula:gridAula"
										rendered="#{varNoturno2.competencia.disciplina.nome != 'Indisponível' 
										and varNoturno2.competencia.disciplina.nome != 'Disponível'}">
										<div align="center" style="width: 80px; color: black">
											#{varNoturno2.competencia.disciplina.nome}</div>
										<f:setPropertyActionListener value="#{varNoturno2}"
											target="#{aulaBean.aula}"></f:setPropertyActionListener>
									</p:commandLink>
								</p:column>
								<p:column
									rendered="#{aulaBean.isSabado(varNoturno2.disponibilidade.dia)}">
									<div style="width: 80px"></div>
								</p:column>




							</p:dataGrid>
						</p:column>
					</p:row>

				</p:panelGrid>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>

</html>